﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;

namespace NuaTarDoneng
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Url.ToString().IndexOf("localhost") > -1)
            {
                PlaceHolder3.Visible = false;
            }
           
            if (Session["User"] == null)
            {
                PlaceHolder1.Visible = true;
                PlaceHolder2.Visible = false;
            }
            else
            {
                PlaceHolder2.Visible = true;
                PlaceHolder1.Visible = false;
                Label1.Text = Session["User"].ToString()+",欢迎你! ";
            }
            
        }

        protected void SignUp_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = "SELECT count(*) FROM [User] WHERE UserName='" + UserName.Text + "' AND PassWord= '" + PassWord.Text + "'";
            cnn.Open();
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            if (i == 1)
            {
                Session.Add("User", UserName.Text);
                if (UserName.Text == "kmlixh")
                {
                    Session.Add("Role", "1z8N7b3c2*9sLfjLIDfd987");
                    Session.Timeout = 60;
                }
                else
                {
                    Session.Timeout = 20;
                }
            }
            
            
            Response.Redirect(Request.Url.ToString());
        }
        public string GetSortN(string a)
        {
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = "select count(*) from blogs where SortID='" + a + "'";
            cnn.Open();
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            cnn.Close();
            return i.ToString();

        }
        public string getShortTitle(string a)
        {
            a = (a.Length < 12) ? a : a.Substring(0, 13)+"...";
            return a;
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            if (Session["Role"] != null && Session["Role"].ToString() == "1z8N7b3c2*9sLfjLIDfd987")
            {
                Response.Redirect("AdminCenter.aspx");
            }
            else
            {
                Response.Redirect("UserCtrol.aspx");
            }
           
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Response.Redirect(Request.Url.ToString());
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

        }
    }
}
